#include<stdio.h>
#include<string.h>
struct Stu
{
	char name[20];
	int i;
};
int cmp(const void* p, const void* q,size_t width)
{
	return ((struct Stu*)p)->i- ((struct Stu*)q)->i;
}

void swap(char* p, char* q, size_t width)
{
	int i = 0;
	for (i = 0; i < width; i++)
	{
		char tmp = *p;
		*p = *q;
		*q = tmp;
		p++;
		q++;
	}
}

void boll_arr(void *base, size_t sz, size_t width, int(*cmp)(const void* p, const void* q))
{
	int i = 0;
	for (i = 0; i < sz - 1; i++)
	{
		int j = 0;
		for (j = 0; j < sz - 1 - i; j++)
		{
			if (cmp((char*)base + j * width, (char*)base + (j + 1) * width) > 0)
				swap((char*)base + j * width, (char*)base + (j + 1) * width, width);
		}
	}
}
void test()
{
	struct Stu arr[] = { {"zhangsan",15},{"lisi",35},{"wangwu",20}};
	size_t sz = sizeof(arr) / sizeof(arr[0]);
	boll_arr(arr, sz, sizeof(arr[0]), cmp);
	int i = 0;
	for (i = 0; i < 3; i++)
	{
		printf("%s %d\n", (arr+i)->name, (arr + i)->i);
	}
}
int main()
{
	test();
	return 0;
}